package net.shopxx.service.impl;

import net.shopxx.common.CommentUtil;
import net.shopxx.service.PayService;
import net.shopxx.util.SystemConfigUtil;

import org.springframework.stereotype.Service;

import chinapnr.SecureLink;

/**
 * Service实现类 - 汇付天下支付接口
 */

@Service
public class HuiPayServiceImpl implements PayService {

	public String getMerId() {
		return "870708";
	}

	public String getMerPrk() {
		return CommentUtil.class.getClassLoader().getResource("").getPath()+"MerPrK870708.key";
	}

	public String getPgPubk() {
		return CommentUtil.class.getClassLoader().getResource("").getPath()+"PgPubk.key";
	}

	public String sign(String signMsg) throws Throwable {
		SecureLink secureLink = new SecureLink();
		int ret = secureLink.SignMsg(getMerId(),getMerPrk(), signMsg);
		if(ret != 0)
		{
			throw new Exception("签名失败");
		}
		return secureLink.getChkValue();
	}

	public String signOrder() {
		return null;
	}

	public boolean verifyAuthToken(String PlainData, String CheckValue) {
		return false;
	}

	public boolean verifyTransResponse(String checkValue,String painText){
		
		SecureLink secureLink = new SecureLink();
		int ret = secureLink.VeriSignMsg(getPgPubk(),painText, checkValue);
		if(ret != 0)
		{
			return false;
		}
		return true;
	}

	public String getPayUrl() {
		return "http://mas.chinapnr.com/gar/RecvMerchant.do";
	}

	public String getRefundUrl() {
		return "http://mas.chinapnr.com/gao/entry.do";
	}
	
	public String getBgRetUrl() {
		return SystemConfigUtil.getSystemConfig().getShopUrl()
		+ "pay/huifu!paynotify.action";
	}

	public String getRefundRetUrl() {
		return SystemConfigUtil.getSystemConfig()
		.getShopUrl()
		+ "pay/huifu!paynotify.action";
	}

	public String getRetUrl() {
		return SystemConfigUtil.getSystemConfig().getShopUrl()
		+ "pay/huifu!paynotify.action";
	}

}